<template>
	<view class="page" :style="{'min-height':h+'px','padding-top':(mt)+'px'}">
		<c-nav-bar1 :title="titles"></c-nav-bar1>
		<view class="bg"></view>
		<view class="content" v-if="list">
			<view class="head">
				<text class="status" v-if="list.orderStatus=='1'">待核销</text>
				<text class="status" v-if="list.orderStatus=='-2'">待支付</text>
				<text class="status" v-if="list.orderStatus=='2'">已核销</text>
				<text class="status" v-if="list.orderStatus=='4'">已取消</text>
				<text class="status" v-if="list.orderStatus=='5'">已退款</text>
				<text style="margin-top: 18rpx; font-size: 26rpx; font-weight: Regular;">￥</text>
				<text style="font-weight: Semibold;">{{list.orderAmount}}</text>
			</view>
			<view class="djs" v-if="list.orderStatus=='-2'&&djsTime">
				<uCountDown text="剩余支付时间：" color="#ffffff" :fontSize="24" @finish="finish" :djsTime="djsTime" />
			</view>
			<view class="ticketInfo">
				<view class="ticketInfo-hander">
					<view class="images">
						<image class="image" :src="list.cover" mode="aspectFill"></image>
					</view>
					<view class="" style="width: 100%; display: flex; flex-wrap: wrap; justify-content: space-between;">
						<view class="name">
							{{list.comboName}}
						</view>
						<view class="date">

							<view class="" style="margin-right: 12rpx;">
								<text v-if="list.comboType==1">
									就餐人数:
								</text>
								<text v-if="list.comboType==2">
									就餐份数:
								</text>
							</view>
							<view class="">
								<view :border="false" v-if="list.comboType==1" style="display: flex;">
									<view class="">
										<text slot="icon" class="txt">成人</text>
										<text slot="title" class="val">{{list.num}}</text>
									</view>
									<view class="" v-if="list.repastNum!=0" style="margin: 0 6rpx;">
										/
									</view>
									<view class="" v-if="list.comboType==1&&list.repastNum!=0">
										<text slot="icon" class="txt">儿童</text>
										<text slot="title" class="val">{{list.repastNum}}</text>
									</view>
								</view>
								<view :border="false" v-if="list.comboType==2">
									<text slot="title" class="val">{{list.num}}</text>
								</view>
							</view>

						</view>
					</view>
				</view>

				<view class="ticketInfo-demo">
					<u-row customStyle="margin-bottom: 10px">
						<u-col span="3">
							<view class="demo-layout bg-purple">
								套餐说明
							</view>
						</u-col>
						<u-col span="9">
							<view class="demo-layout bg-purple-light">
								{{list.comboExplain}}
							</view>
						</u-col>
					</u-row>
				</view>
			</view>


			<view class="voucherCode" v-if="list.orderStatus==1">
				<view class="title">
					<text>凭证码</text>
					<text class="orange">凭二维码直接验证使用</text>
				</view>
				<view class="codeList">
					<view class="ci_code">
						<image style="width:300rpx;height:300rpx;" :src="list.qrCode"></image>
					</view>
					<view class="ci_bottom">
						<view class="" style="margin: 0 auto;">
							<!-- 待核销({{list.guestName}}) -->
							<text slot="icon" class="txt">预约时间：</text>
							<text slot="title" class="val">{{list.repastTime}}</text>
						</view>
					</view>

				</view>
			</view>
			<view class="voucherCode_colse">
				<view class="codeList">
					<view class="title_info">
						<text>商户信息</text>
					</view>

					<!-- <view class="listItem" v-for="(item,index) in object.passengersList" :key="index"> -->
					<view class="listItemed">
						<view class="name">
							{{list.homestayName}}
						</view>
						<view
							style="display: flex; justify-content: space-between; align-items: center; margin-top: 16rpx;">
							<view class="" style="width: 75%; color: #808080; font-size: 28rpx; font-weight: Regular;">
								{{list.areaDetail}}
							</view>
							<view class="" style="width: 25%; display: flex;align-items: center; ">
								<span style="margin: auto; width: 42rpx; height: 42rpx;" @click="navigation(list)">
									<image style="width: 100%; height: 100%;"
										src="https://i.ringzle.com/file/20240418/a64522916495447d8f3deb2892dc9b64.png"
										mode=""></image>
								</span>
								<span style="margin: auto; width: 42rpx; height: 42rpx;" @click="pHone(list)">
									<image style="width: 100%; height: 100%;"
										src="https://i.ringzle.com/file/20240418/55badc32179348f2b023a04ba626a49d.png"
										mode=""></image>
								</span>
							</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 订单信息 -->
			<view class="orderInfo">
				<view class="tit">订单信息</view>
				<u-cell :border="false">
					<text slot="icon" class="txt">订单编号</text>
					<text slot="title" class="val">{{list.orderCode}}</text>
					<text slot="right-icon" class="icon"
						style="border: 1rpx solid #007A69; border-radius: 50rpx; box-sizing: border-box; color: #007A69;padding: 2rpx 10rpx; font-size: 22rpx; font-weight: Regular;"
						@tap="copyOrderNo(list)">复制</text>
				</u-cell>

				<u-cell :border="false" v-if="list.orderStatus==2">
					<text slot="icon" class="txt">核销时间</text>
					<text slot="title" class="val">{{list.checkinTime}}</text>
				</u-cell>
				<u-cell :border="false">
					<text slot="icon" class="txt">预约人姓名</text>
					<text slot="title" class="val">{{list.guestNameCopy}}</text>
				</u-cell>
				<u-cell :border="false">
					<text slot="icon" class="txt">预约手机号</text>
					<text slot="title" class="val">{{list.guestPhoneCopy}}</text>
				</u-cell>
				<u-cell :border="false">
					<text slot="icon" class="txt">备注</text>
					<text slot="title" class="val">{{list.remarks==null?'':list.remarks}}</text>
				</u-cell>
				<u-cell :border="false">
					<text slot="icon" class="txt">合计金额</text>
					<text slot="title" class="val">{{list.orderAmount}}</text>
				</u-cell>
			</view>

		</view>
		<view class="btns">
			<template v-if="list.orderStatus==1">
				<view class="" @click="toStatus0">
					取消订单
				</view>
				<view class="" @click="applyAfterSales(list)"
					style="color:#fff ; border-color: #007A69; background-color: #007A69;">
					再次预订
				</view>
				<!-- 	<view class="" style="color:#fff ; border-color: #007A69; background-color: #007A69;"
					@click="toStatus1(list)">
					开发票
				</view> -->
			</template>
			<template v-if="list.orderStatus==-2">
				<view class="" @click="toStatus0">
					取消订单
				</view>
				<view class="" @click="pay" style="color:#fff ; border-color: #007A69; background-color: #007A69;">
					立即支付
				</view>
			</template>
			<template v-if="list.orderStatus==5||list.orderStatus==4">
				<view class="" @click="deleteOrder(list)">
					删除订单
				</view>
				<!-- 			<view @click.stop="toEvaluate(list)" v-if="list.isComment==1"
					style="color:#fff ; border-color: #007A69; background-color: #007A69;">
					评价
				</view> -->
				<view class="" style="color:#fff ; border-color: #007A69; background-color: #007A69; width: 100%;"
					@click="applyAfterSales(list)">
					再次预订
				</view>
			</template>

			<template v-if="list.orderStatus==2">
				<view class="" @click="deleteOrder(list)">
					删除订单
				</view>
				<view @click.stop="toEvaluate(list)" v-if="list.isComment==1"
					style="color:#fff ; border-color: #007A69; background-color: #007A69;">
					评价
				</view>
				<view class="" style="color:#fff ; border-color: #007A69; background-color: #007A69; width: 100%;"
					@click="applyAfterSales(list)">
					再次预订
				</view>
			</template>


		</view>
		<u-toast ref="uToast"></u-toast>

		<!-- 取消弹框 -->
		<u-modal :show="showAgree" :title="title" :content='content' showCancelButton="true" confirmText='确定'
			confirmColor='#007A69' @confirm="confirm" @cancel='cancel'></u-modal>


		<!-- 删除弹框 -->
		<u-modal :show="showdelete" :title="title" :content='contented' showCancelButton="true" confirmText='确定'
			confirmColor='#007A69' @confirm="confirmed" @cancel='cancel'></u-modal>

	</view>

</template>

<script>
	export default {
		data() {
			return {
				titles: '订单详情',
				h: uni.getSystemInfoSync().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				value: 1,
				status: 1,
				id: '',
				list: '',
				bedData: {},
				id: '',
				arriveTime: '',
				arriveTimes: '',
				leaveTime: '',
				leaveTimes: '',
				count: '',
				orderId: '',
				price: '',
				form: {
					initiator: 2,
					orderCode: '',
					status: ''
				},
				num: 0,

				showAgree: false,
				checkInTimeStart: '',
				checkOutTime: '',
				title: '温馨提示',
				content: '您确定要取消吗？确定取消将不可撤回，再次预订可能影响您用餐！',
				checkInRooms: 0,
				djsTime: 0,
				showdelete: false,
				orderType: null,
				delId: null,
				contented: '您确定要删除吗？确定删除将不可撤回！',
			}
		},
		onLoad(option) {
			this.id = option.orderId
			this.getList()
		},
		methods: {
			toEvaluate(item) {
				uni.navigateTo({
					url: '/pagesMy/appraise/appraise3?obj=' + JSON.stringify(item),
				});
			},
			copyOrderNo(no) {
				let that = this;
				// #ifdef H5
				this.$copyText(no).then(res => {
					this.$showToast('复制成功');
				})
				// #endif
				// #ifdef MP-WEIXIN
				uni.setClipboardData({
					data: no,
					success(res) {
						that.$showToast('复制成功');
					},
					fail(err) {
						that.$showToast('复制失败');
					}
				})
				// #endif
			},
			// 导航
			navigation(item) {
				// let lat = item.lat
				// let lon = item.lon
				uni.openLocation({
					latitude: Number(item.lat),
					longitude: Number(item.lon),
					name: item.homestayName,
				});
			},
			// 拨打电话。
			pHone() {
				uni.makePhoneCall({
					phoneNumber: this.list.landlinePhone //仅为示例
				});
			},
			// 获取详情
			getList() {
				this.$api.get(`/api/repast/getRepastOrderInfo/${this.id}`)
					.then(res => {
						this.list = res.data.data;
						if (this.list.orderStatus == '-2') {
							let diffMS = Date.parse(new Date()) - Date.parse(new Date(this.list.createDate));
							if (diffMS < this.$gqTime) this.djsTime = this.$gqTime - diffMS - 1000; //提前一秒，便于取消刷新
						}
						this.list.guestNameCopy = this.$aesTm.tuomin(this.list.guestName, 1);
						this.list.guestPhoneCopy = this.$aesTm.tuomin(this.list.guestPhone, 2);
					})
			},
			// 立即支付	
			pay() {
				var list = JSON.stringify({
					price: this.list.orderAmount,
					orderId: this.id
				})
				this.$api.post('/order/icbc/createOrder', {
					orderCode: this.list.orderCode,
					tradeType: 'JSAPI',
					openId: JSON.parse(uni.getStorageSync('userInfo')).openId
				}, false).then(res => {
					if (res.statusCode == 200 && res.data != null) {
						this.payShow = false;
						this.$wxPay(res.data).then(result => {
							uni.redirectTo({
								url: '/pagesTrip/hotel/details/paymentSuccess?list=' + list
							})


						})
					} else this.$showModal(res.data.msg);

				})
			},

			// 取消订单
			toStatus0() {
				this.showAgree = true
			},
			//确定取消
			confirm() {
				this.agree = true
				this.showAgree = false
				this.form.orderCode = this.list.orderCode
				this.form.status = this.list.orderStatus
				this.$api.post('/api/repast/cancelRepastOrder', this.form).then(res => {
					// uni.navigateBack(1)
					if (res.data.code == 0) {
						uni.redirectTo({
							// url: '/pagesMy/order/index',
							url: '/pagesMy/order/index?name=酒店民宿&type=0&typeIndex=1'
						})
						this.getList()
					} else this.$showModal(res.data.msg);
				})
			},
			// 取消
			cancel() {
				this.showAgree = false
			},




			// 取消
			cancel() {
				this.showAgree = false
			},
			// 删除订单
			deleteOrder(item) {


				this.showdelete = true
				this.delId = item.id


			},
			// 确定删除
			confirmed() {
				let id = this.delId
				this.$api.get(`/api/hotel/delOrder/${id}`).then((res) => {
					if (res.data.code == 0) {
						this.showdelete = false
						setTimeout(() => {
							this.$showToast('删除成功');
							setTimeout(() => {
								uni.redirectTo({
									url: '/pagesMy/order/index?name=酒店民宿&type=0&typeIndex=1'
								})
							}, 500)
						}, 500)

						// this.getList();
					} else {
						this.$showModal(res.data.msg);
						this.showdelete = false
						// this.getList();
					}
				})
			},



			// 申请退款
			// GoRefund() {
			// 	uni.redirectTo({
			// 		url: '/pagesTrip/hotel/refund/index?list=' + JSON.stringify([{
			// 			...this.list
			// 		}])
			// 	})
			// },
			// 再次预定
			applyAfterSales(item) {
				// 初始化
				let arriveDate = new Date().Format('yyyy-MM-dd')
				let mt = new Date().setDate(new Date().getDate() + 1);
				let leaveDate = new Date(mt).Format('yyyy-MM-dd')
				uni.navigateTo({
					url: "/pagesTrip/hotel/details/index?list=" +
						JSON.stringify([{
							homestayId: item.homestayId,
							name: '',
							arriveDate: arriveDate, //	到达时间(yyyy-MM-dd)
							leaveDate: leaveDate, //离开时间(yyyy-MM-dd)
						}, ]),
				});
			},
			finish() {
				this.form.refundReason = '超时未支付,自动取消!';
				this.$api.post('/api/repast/cancelRepastOrder', this.form).then(res => {
					if(res.data.code==0){
						setTimeout(() => {
						uni.reLaunch({
							url: '/pagesMy/order/index?name=酒店民宿&type=0&typeIndex=1'
						})
						},1000)
					}
					// setTimeout(() => {
					// 	this.djsTime = 0;
					// 	this.getList();
					// }, 500)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.listItemed {
		padding: 13rpx 0;
		font-size: 26rpx;
		color: #666;
		align-items: center;

		.name {
			font-size: 28rpx;
			color: #111111;
			font-weight: bold;
		}

		.verityInfo {
			margin: 30rpx 0;
			line-height: 28rpx;
			height: 28rpx;
		}

		.top {
			margin-bottom: 30rpx;
		}

		.ticketType {
			margin-left: 20rpx;
			font-weight: 400;
			color: #94A9C8;
			line-height: 33rpx;
			height: 33rpx;
			font-size: 24rpx;
			background: #F5F8FA;
			border-radius: 8rpx;
			padding: 4rpx;
		}
	}

	.voucherCode_colse {
		padding: 20rpx;

		.title {

			height: 80rpx;
			font-weight: 600;
			font-size: 31rpx;
			color: #333;
			padding: 20rpx 30rpx;
			line-height: 80rpx;
			background: #fff;
			border-radius: 20rpx;
		}

		.title_info {
			line-height: 80rpx;
			font-weight: 600;
			font-size: 34rpx;
			color: #333;
			// padding: 0 10rpx;
		}

		.codeList {
			// margin-top: 19rpx;
			padding: 20rpx;
			background: #fff;
			border-radius: 20rpx;
		}

		.listItem {
			display: flex;
			justify-content: space-between;
			padding: 13rpx 19rpx;
			flex-direction: row;
			font-size: 26rpx;
			color: #666;
			align-items: center;

			.verityInfo {
				margin: 30rpx 0;
				line-height: 28rpx;
				height: 28rpx;
			}

			.top {
				margin-bottom: 30rpx;
			}

			.ticketType {
				margin-left: 20rpx;
				font-weight: 400;
				color: #94A9C8;
				line-height: 33rpx;
				height: 33rpx;
				font-size: 24rpx;
				background: #F5F8FA;
				border-radius: 8rpx;
				padding: 4rpx;
			}


		}
	}

	.ci_bottom {
		text-align: center;
		width: 100%;
		padding: 0 24rpx 30rpx;
		box-sizing: border-box;
		font-weight: 600;
		font-size: 30rpx;
		color: #111111;
		// display: flex;
		// justify-content: space-between;

	}

	.ci_code {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.voucherCode {
		margin: 20rpx 23rpx 0;
		padding: 44rpx 24rpx 20rpx;
		border-radius: 20rpx;
		background-color: #fff;
		z-index: 2;

		.title {
			font-weight: 600;
			font-size: 34rpx;
			color: #333;
		}

		.orange {
			margin: 0 30rpx;
			font-weight: Regular;
			font-size: 24rpx;
			color: #AAAAAA;
		}
	}

	.bottom-list {
		display: flex;
		margin: 37rpx auto;
		justify-content: center;

		.image {
			width: 36rpx;
			height: 36rpx;
			margin: 0 8rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.text {
			font-size: 26rpx;
			color: #999999;
			font-weight: Regular;
		}
	}

	.minus,
	.plus {
		display: flex;
		align-items: center;
		// width: 44rpx;
		// height: 44rpx;
		// line-height: 44rpx;
		padding: 10rpx 10rpx;
		// padding-left: 8rpx;

		border: 1px solid #999;
		border-radius: 6rpx;
		text-align: center;
	}

	.page {
		box-sizing: border-box;
		background-color: #F5F8FA;


		.content {
			position: relative;
			z-index: 3;
			padding-bottom: 160rpx;

			.hand-title {
				position: absolute;
				left: 20rpx;
				top: 100rpx;
				font-size: 24rpx;
				color: #fff;
			}
		}

	}

	.bg {
		height: 700rpx;
		position: fixed;
		// top: 44px;
		z-index: 1;
		width: 100%;
		background-image: linear-gradient(to bottom, #007A69, #007A69, #F5F8FA);
	}

	.ticketInfo-demo {
		// border-bottom: 2rpx solid #EFEFEF;
		margin-top: 40rpx;

		.bg-purple {
			font-size: 26rpx;
			color: #808080;
			font-weight: Regular;
		}

		.bg-purple-light {
			font-size: 30rpx;
			color: #111111;
			font-weight: Regular;
		}
	}

	.two-center-two {
		box-sizing: border-box;

		.tit {
			font-size: 32rpx;
			color: #333333;
			margin: 20rpx 0;
		}

		.df-one {
			font-size: 32rpx;
			color: #333333;
			font-weight: bold;

			// .bg-purple-dark {
			// 	margin-left: 140rpx;
			// }

			// .demo-layout {
			// 	margin-left: 30rpx;
			// }
		}

		.df-two {
			border-bottom: 2rpx solid #EFEFEF;

			.bg-purple {
				// margin-right: 100rpx;
				width: 182rpx;
				margin-left: -13rpx;
			}

			.bg-purple-dark {
				// margin-left: 50rpx;
			}

			.bg-purple,
			.bg-purple-dark {
				font-size: 26rpx;
				color: #777777;
				font-weight: Regular;
				text-align: center;

				text {
					margin: 0 8rpx;
				}
			}

			.bg-purple-light {
				font-size: 24rpx;
				color: #666666;
				border: 1rpx solid #666666;
				text-align: center;
				border-radius: 50rpx;
			}

		}
	}


	.prices-content {
		margin: 24rpx 0;

		.txt1 {
			font-size: 32rpx;
			color: #111111;
			font-weight: bold;
		}

		.txt2 {
			margin: 12rpx 0;
			font-size: 26rpx;
			color: #777777;
			font-weight: Regular;
		}

	}



	.orderInfo {
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 16rpx;
		width: 96%;
		margin: 0 auto 20rpx;
		padding: 0 0 30rpx;

		.tit {
			font-size: 32rpx;
			color: #333;
			padding-left: 30rpx;
			padding-top: 40rpx;
			font-weight: 600;
			margin-bottom: 20rpx;
		}

		.txt {
			font-size: 28rpx;
			color: #666;
			width: 140rpx;
		}

		.icon {
			font-size: 28rpx;
			color: #666;
		}

		.val {
			font-size: 28rpx;
			color: #333333;
			margin: 0 20rpx 0 30rpx;
			font-weight: Regular;
		}

	}

	.ticketInfo {
		box-sizing: border-box;
		width: 96%;
		margin: 0 auto 20rpx;
		padding: 44rpx 24rpx 10rpx;
		border-radius: 20rpx;
		position: relative;
		background-color: #fff;
		z-index: 2;

		.ticketInfo-hander {
			display: flex;

			.images {
				width: 136rpx;
				height: 136rpx;
				border-radius: 12rpx;
				margin-right: 20rpx;

				.image {
					border-radius: 12rpx;
					// width: 100%;
					// height: 100%;
					width: 136rpx;
					height: 136rpx;
				}
			}

		}

		.name {
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
			width: 100%;
		}

		.date {
			// padding: 20rpx 0 32rpx;
			padding-top: 30rpx;
			font-size: 28rpx;
			color: #666666;
			font-weight: Regular;
			display: flex;
		}



		.topHead {
			width: 96%;
			margin: 0 auto;
			background-color: #F5F8FA;
			padding: 28rpx 0 28rpx 84rpx;
			border-radius: 16rpx;
			position: relative;

			text {
				position: absolute;
				left: 0;
				top: 0;
				z-index: 1;
				border-radius: 16rpx 0 0 16rpx;
				width: 48rpx;
				color: #fff;
				font-size: 20rpx;
				background-color: #484F61;
				text-align: center;
				height: 100%;
				padding: 15rpx 10rpx 0;

			}

			.p {
				font-size: 28rpx;
				color: #333;

				&:nth-of-type(1) {
					font-weight: 600;
					margin-bottom: 16rpx;
				}
			}


		}

		.code {
			margin-top: 40rpx;
			text-align: center;
			position: relative;

			.cover,
			.sx {
				position: absolute;
				background-color: rgba(255, 255, 255, 0.5);
				width: 340rpx;
				height: 340rpx;
				top: 66rpx;
				left: 50%;
				transform: translate(-50%, 0);
			}

			.sx {
				width: 120rpx;
				height: 120rpx;
				top: 150rpx;
				background: transparent;
			}

			.txt {
				font-size: 28rpx;
			}

			image {
				width: 340rpx;
				height: 340rpx;
				margin: 30rpx 0;
			}
		}
	}

	.head {
		box-sizing: border-box;
		padding: 34rpx 24rpx 40rpx;
		display: flex;
		position: relative;
		z-index: 2;

		text {
			color: #fff;

			&:nth-child(1),
			&:nth-child(3) {
				font-size: 44rpx;
				font-weight: bold;
			}

			&:nth-child(2) {
				flex: 1;
				text-align: right;
				width: 100px;
				font-size: 36rpx;
			}
		}
	}

	.djs {
		width: calc(100% - 88rpx);
		padding: 0 20rpx;
		margin-bottom: 35rpx;
		position: relative;
	}

	.btns {
		box-sizing: border-box;
		width: 100%;
		position: fixed;
		bottom: 0;
		z-index: 4;
		left: 0;
		display: flex;
		padding: 32rpx 32rpx 50rpx;
		background-color: #fff;
		gap: 0 20rpx;
		box-shadow: 0 -8rpx 16rpx rgba(0, 0, 0, 0.06);


		&>view {
			width: calc(50% - 15rpx);
			height: 80rpx;
			border-radius: 46rpx;
			// border: 1rpx solid #999999;
			line-height: 80rpx;
			text-align: center;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: Bold;
			color: #111111;
			background-color: #F6F6F6;
		}
	}
</style>